package com.hejia.alauda.persistence.mybatis;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import com.hejia.alauda.entity.BankCard;
import com.hejia.alauda.persistence.BaseMapper;

public interface BankCardMapper extends BaseMapper<BankCard> {

	/**
	 * 查找银行卡
	 * 
	 * @param map
	 * @return 银行卡列表
	 */
	List<BankCard> selectBankCardsByKeyword(Map<String, Object> map);

	/**
	 * 统计银行卡
	 * 
	 * @param map
	 * @return
	 */
	Integer countBankCardsByKeyword(Map<String, Object> map);

	@Select("select b.* from `order` a ,`bankcard` b where str_to_date(a.createdate,'%Y-%m-%d')>=#{0} and #{1}>=str_to_date(a.createdate,'%Y-%m-%d') and a.`bankcard_id`=b.id GROUP BY b.`bankCode`;")
	@ResultType(value = Map.class)
	public List<BankCard> bankCardByDate(String startdate, String enddate);

	@Select("select b.* from `order` a ,`bankcard` b where a.`bankcard_id`=b.id GROUP BY b.`bankCode`;")
	@ResultType(value = Map.class)
	public List<BankCard> allBankCardByDate();

	@Select("select b.* from bankcard b join user u on b.user_id = u.id where u.`id`=#{0}")
	@ResultType(value = Map.class)
	public List<BankCard> getBankCardsByUserid(Long id);

	/**
	 * 统计支付网关银行卡单月已支付金额
	 * @param bankCardId	银行卡ID
	 * @param pagGateCode	支付网关代码
	 * @param startTime		开始时间
	 * @param endTime		结束时间
	 * @return	单月已支付金额
	 */
	Long countPayGateBankCardPaidAmountByDate(
			@Param("bankCardId") Long bankCardId,
			@Param("pagGateCode") String pagGateCode,
			@Param("startTime") Date startTime,
			@Param("endTime") Date endTime);

}
